home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
atob11.zip
/
ATOB.ASM
next >
Wrap
Assembly Source File
|
1990-09-07
|
27KB
|
789 lines
;*************************************************************************
;
; atob.asm: Fast assembly-language version of atob.c
; Version 1.1
;
; atob converts files from ascii to binary, undoing the encoding
; of btoa.
;
; USAGE:
; atob output.fil <input.fil
;
; DESCRIPTION:
;
; atob reads its stdin and sends its output to the designated output file.
; If it already exists, the output file is overwritten *without*warning*.
;
; The encoding is performed by the program btoa. The btoa/atob encoding
; has a 25% expansion rate (as opposed to 33% by uudecode). Simple error
; checking is performed at the end to confirm that the entire file was
; decoded correctly. No attempt to localize the error is made. Btoa/atob
; is suitable only for ASCII transmission and hence is not appropriate for
; USENET transmission of binaries.
;
; I use btoa/atob to transfer binary files from a UNIX host to my IBM PC
; over a seven-bit channel, using the command line
;
; btoa < desired.fil | kermit -s -
;
; receiving the file in MS-Kermit, then decoding it on my IBM PC. This is
; faster than sending the binary directly since kermit uses eighth-bit quoting
; which essentially means that it takes 50% longer to transmit binaries
; as compared to ASCII files.
;
; I have used this program to decode dozens of binaries (including some
; ridiculously huge ones) and they all decoded fine, so I'm pretty certain
; that the bugs have been stomped out. If you find one, contact me at the
; email address below.
;
; SPEED:
;
; rjb = Ray Berry's version of atob (1/21/89)
; v10 = Version 1.0 of my atob
; v11 = Version 1.1 of my atob
;
; Time to decode Ralf Brown's interrupt list (inter490.zoo) on a PC-XT:
;
; rjb = 1583 seconds (26 min 23 sec)
; v10 = 113 seconds ( 1 min 53 sec) Speedup: 14x
; v11 = 70 seconds ( 1 min 10 sec) Speedup: 22x [1.6x faster than v10]
;
;
; ENCODING:
;
; Four bytes from the input are viewed as a 32-bit integer and converted
; to base 85. "!" represents zero, the double-quote represents 1, and
; so on up to "u" representing 84. As a special case, the 32-bit number
; zero is represented by the single character "z". The file is headed
; by the string "xbtoa Begin" and is followed by
;
; xbtoa End N Clen Clen E Ceor S Csum R Crot
;
; where Clen is the length of the encoded file (first in decimal, then
; in hex) and Ceor, Csum and Crot are three checksums (encoded in hex).
; Csum is Clen plus the sum of the characters. Ceor is the exclusive-or
; of all the characters, and Crot is a checksum computed via the formula
;
; Crot = (Crot rotated left one bit) + next_character
;
; These are crude checksums (not as robust as, say, CRC).
;
; IMPLEMENTATION:
;
; The program is pretty much a straightforward implementation of the
; decoding algorithm in assembly. Of course, it is rather heavily
; hand-optimized. In particular, SI and DI are used as global register
; values and inline macros are used rather frequently. The only room
; for improvement I can think of is replacing the multiply-by-85
; with a shift-and-add algorithm. (Which might even be slower on
; the 80386, whose multiplication algorithm has been pretty well-
; optimized.)
;
; HOW TO MAKE IT:
;
; If you have TLINK If you have MS's LINK
; ----------------- ---------------------
; masm atob; masm atob;
; tlink atob; link atob;
;
; DISCLAIMER/COPYRIGHT:
;
; As usual, the author claims no responsibility for the behavior of
; the program, although he is pretty sure that it works fine.
;
; The program remains Copyright 1990 by Raymond Chen, but I make
; no attempt to restrict distribution in any form. Just don't try
; to pass it off as your own. This copyright is of dubious legal
; significance since the string "Copyright" appears nowhere in the
; binary. I don't care. If you want to violate my copyright, there
; isn't too much I can do to stop you.
;
; AUTHORSHIP:
;
; The program was written by Raymond Chen (raymond@math.berkeley.edu)
; in January 1990 or thereabouts.
;
; And now... The code:
name atob
;*************************************************************************
; General equates
;*************************************************************************
DOSvec equ 21h ; DOS interrupt service vector
stdin equ 0 ; DOS file handle
print equ 9 ; Print a string to the console
creat equ 3ch ; Create a new file
close equ 3eh ; Close a file
read equ 3fh ; Read from a handle
write equ 40h ; Write to a handle
exit equ 4ch ; End the process
openflg equ 20h ; read-only, deny write
cr equ 0dh
lf equ 0ah
bufsiz equ 10240 ; size of I/O buffers.
; five times it must be less than 64K.
; 5 = 4 + 1. 1 = a copy of the incoming data.
; 4 = each "z" codes four output bytes.
; worst case expansion is when somebody btoa's a
; file consisting entirely of zeros.
;*************************************************************************
; Global register assignments:
;
; SI = where to get the next byte from the input buffer
; DI = where to send next byte to the output buffer
; BP = What byte number within a block of four? (bcount)
;*************************************************************************
;*************************************************************************
; Segmentation nonsense.
;*************************************************************************
_TEXT segment byte public 'CODE'
_TEXT ends
_DATA segment word public 'DATA'
_DATA ends
_BSS segment word public 'BSS'
_BSS ends
_BSSEND segment byte public 'STACK'
_BSSEND ends
_STACK segment stack 'STACK'
dw 64 dup (?)
_STACK ends
DGROUP GROUP _DATA, _BSS, _BSSEND
;*************************************************************************
; Initialized Global Variables
;*************************************************************************
_DATA segment word public 'DATA'
ClenL dw 0 ; Length of converted file
ClenH dw 0
Ceor label byte ; Checksum via exclusive or
CeorL dw 0
CeorH dw 0
Csum label dword ; Checksum via summation
CsumL dw 0 ; Low word
CsumH dw 0 ; High word
Crot label dword ; Checksum via rotation
CrotL dw 0 ; Low word
CrotH dw 0 ; High word
_DATA ends
;*************************************************************************
; Uninitialized Global Variables
;*************************************************************************
_BSS segment word public 'BSS'
fdout label word
dw 1 dup (?) ; File handle for output
numbuf label byte
db 10 dup (?) ; Numbers go here for decoding
inbuf label byte
db bufsiz dup (?) ; file input buffer
db 1 dup (?) ; the extra byte is for a sentinel
outbuf label byte
db 4*bufsiz dup (?); file output buffer
_BSS ends
;*************************************************************************
; Macros
;*************************************************************************
;*************************************************************************
; makestr: Create a string with the specified label.
; The optional third argument receives the length of the string.
;*************************************************************************
makestr macro l, s, c
_DATA segment word public 'DATA'
l db s
ifnb <c>
c equ $-l
endif
_DATA ends
endm
;*************************************************************************
; die: Print a message and terminate